package world;

import utils.ProgressHandler;
import utils.ProgressHandler.status;
import globalObjects.Player;

import com.jme.scene.Node;
import com.jmex.game.state.BasicGameState;
import com.jmex.game.state.GameStateManager;

//TODO Add pixel stars to make it look more like space
//TODO Add cleanup support

public class WorldGameState extends BasicGameState{
	
	Player player = new Player(.25f);
	Node playerNode = player.getPlayer(5,5,5);
	ProgressHandler ph = new ProgressHandler("Loading");

	
	public WorldGameState() {
		super("World Home");
		init();
		player.initXControls();
		player.initZControls();
	}

	private void init() {
		House house = new House();
		WorldStar star = new WorldStar();

		Node starNode = star.getStar();
		starNode.setLocalTranslation(0, 70, 0);	
		rootNode.attachChild(house.getHouse());
		rootNode.attachChild(starNode);
		rootNode.attachChild(playerNode);
		
		rootNode.updateRenderState();
		rootNode.updateGeometricState(0,true);
		
		//Show the progress handler
		GameStateManager.getInstance().attachChild(ph);
		ph.setActive(true);
	}
	@Override
	public void update(float tpf) {
		player.handleControls();
		rootNode.updateGeometricState(tpf, true);
		phDemo();
	}

	private void phDemo() {
		if (playerNode.getLocalTranslation().x >= 5){
			ph.setStatus(status.YELLOW);
		}
		if (playerNode.getLocalTranslation().x <= 5){
			ph.setStatus(status.GREEN);
		}
		if (playerNode.getLocalTranslation().z >= 5){
			ph.setStatus(status.RED);
		}
		if (playerNode.getLocalTranslation().z <= 5){
			ph.setStatus(status.GREEN);
		}
	}


}
